<?php

namespace app\api\controller;

use app\api\model\WxappPage;
use think\Db;
use app\common\model\Region as RegionModel;
/**
 * 页面控制器
 * Class Index
 * @package app\api\controller
 */
class Page extends Controller {
    /**
     * 页面数据
     * @param null $page_id
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index($page_id = null) {
        // 页面元素
        $data = WxappPage::getPageData($this->getUser(false), $page_id, $this->loca);
        return $this->renderSuccess($data);
    }

    public function get_store() {
        $lng_lat = $this->request->param();

        $data = WxappPage::getPageStore($this->getUser(false), $lng_lat);

        return $this->renderSuccess($data);
    }
    public function get_store_detail($shop_id) {

        $data = WxappPage::getPageStoreDetail($shop_id);

        return $this->renderSuccess($data);
    }
    public function get_clerk_detail($clerk_id) {

        $data = Db::name('store_shop_clerk')->alias('s')
            ->join('upload_file f', 'f.file_id=s.logo_image_id')
            ->join('store_shop st', 'st.shop_id=s.shop_id')
            ->field('s.*,f.file_name,st.shop_name')
            ->where('s.is_delete', 0)
            ->where('s.clerk_id', $clerk_id)->find();
        $data['logo_image'] = base_url() . 'uploads/' . $data['file_name'];

        return $this->renderSuccess($data);
    }


    /**
     * 
     */
    public function getRegion()
    {
       $data = RegionModel::apiPublicCity();
       return $this->renderSuccess($data);
    }

    /**
     * 
     */
    public function getCityId()
    {
        $lng = $this->request->param('lng', 0);
        $lat = $this->request->param('lat', 0);
        $result = \app\api\model\LbsModel::lbsApi($lat,$lng);
        return $this->renderSuccess($result);
    }

}
